package me.maiz.babyisland.web;


import me.maiz.babyisland.es.ProductRepository;
import me.maiz.babyisland.es.entity.ProductDocument;
import me.maiz.babyisland.es.ProductRepository;
import me.maiz.babyisland.es.entity.ProductDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import me.maiz.babyisland.web.BaseController;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Optional;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lucas
 * @since 2019-05-28
 */
@Controller
public class ProductController extends BaseController {

    @Autowired
    private ProductRepository productRepo;

    @RequestMapping("product")
    public String product(){
        return "product";
    }


    @RequestMapping("save")
    public String save(){
        ProductDocument pd = new ProductDocument();
        pd.setId(1);
        pd.setCategoryId(1);
        pd.setDescription("阿斯顿发送到发送到发送到");
        pd.setProductName("一本书");
        ProductDocument save = productRepo.save(pd);
        return "product";
    }


    @RequestMapping("get")
    @ResponseBody
    public ProductDocument get(int id){

        Optional<ProductDocument> save = productRepo.findById(id);
        return save.get();
    }

}

